package com.nineclock.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nineclock.system.pojo.SysCompanyUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;

import java.util.List;


public interface SysCompanyUserMapper extends BaseMapper<SysCompanyUser> {

    /**
     * 根据企业ID 更新企业员工的公司名称
     * @param companyName
     * @param companyId
     */
    @Update("update sys_company_user set company_name = #{companyName} where company_id = #{companyId}")
    void updateCompanyUserByCompanyId(@Param("companyName") String companyName,
                                      @Param("companyId") Long companyId);

    /**
     * 根据企业ID, 查询该企业的主管理员
     * @param companyId
     * @return
     */
    @Select("select \n" +
            "u.* \n" +
            "from \n" +
            "sys_company_user u, \n" +
            "sys_company_user_role ur, \n" +
            "sys_role r \n" +
            "where \n" +
            "u.id = ur.company_user_id \n" +
            "and ur.role_id = r.id \n" +
            "and ur.company_id = #{companyId} \n" +
            "and r.role_name = 'ROLE_ADMIN_SYS'")
    public SysCompanyUser queryCurrentAdminByCompanyId(@Param("companyId") Long companyId);

    /**
     * 查询工号是否被占用
     * @param workNumber
     * @return
     */
    @Select(" select count(*) from sys_company_user where mobile = #{workNumber} ")
    public int checkWorknumber(@Param("workNumber") String workNumber);
}
